Skip to content

Implement Content-Length Header in the Blocking API#4124

Closed
Lexazan wants to merge 1 commit intooobabooga:mainfrom
Lexazan:blocking_api-with-content-length-header
Closed

Implement Content-Length Header in the Blocking API#4124
Lexazan wants to merge 1 commit intooobabooga:mainfrom
Lexazan:blocking_api-with-content-length-header

Conversation

@Lexazan
Copy link
Copy Markdown

@Lexazan Lexazan commented Sep 29, 2023

Implement Content-Length Header in the Blocking API

I have made changes to the API's response behavior. Previously, the API would send headers first, followed by the body when it was generated. However, I have modified it to wait until the body is fully generated before sending both the headers and the body together. Additionally, I have included the Content-Length header in accordance with the recommendations outlined in the HTTP 1.0 protocol specification.

The reason behind this adjustment stems from an issue I encountered while calling the API from the Godot game engine. In the previous setup, the game engine was not waiting for the complete body but instead emitted the data_received event immediately after receiving the headers. There are most likely other API clients exhibiting similar behavior, and this change should improve compatibility with them while also eliminating any head-scratching for those who are implementing it.

Checklist:

@Lexazan Lexazan changed the title Update to Implement Content-Length Header in the Blocking API Implement Content-Length Header in the Blocking API Sep 29, 2023
@teddybear082
Copy link
Copy Markdown

I just stumbled upon this, in case it’s helpful I have example code for using textgenwebui’s OpenAI extension in streaming mode in Godot here: https://github.com/teddybear082/godot4-ai-npc-example/blob/main/addons/textgenwebuiOpenAI/TextgenwebuiOpenAI.gd. I know it’s not the same as what you are talking about but figured I would pass along as I had a problem with any streaming API service with Godot’s built in httprequest nodes and struggled with it for quite some time.

@oobabooga
Copy link
Copy Markdown
Owner

The current API will be deprecated and replaced with the OpenAI-compatible one, which now uses FastAPI after #4430.

I assume the behavior described in this PR may be correct by default in FastAPI; if not, a new PR would be welcome.

@oobabooga oobabooga closed this Nov 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants